package cn.hnu.qq.frame;

import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel;

import cn.hnu.qq.client.controller.CenterController;
import cn.hnu.qq.client.panel.LogonPanel;

public class ClientFrame extends JFrame{
	
	public ClientFrame(){
		init();
//		EventQueue.invokeLater(new Runnable() { //渲染
//			public void run() {
//				try  {
//				      UIManager.setLookAndFeel( new  SubstanceOfficeBlue2007LookAndFeel());
//				      JFrame.setDefaultLookAndFeelDecorated( true );
//				      JDialog.setDefaultLookAndFeelDecorated(true);
//				      
//				    }  catch  (Exception e) {
//				      System.out.println( " Substance Raven Graphite failed to initialize " );
//				    }
//			}
//		});
	}
	
	private void init() {
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		try {
			setIconImage(ImageIO.read(new File("src/main/java/image/xiaohui.jpg")));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	

	public ClientFrame(JPanel panel){
//		this.menubar.setVisible(false);
		
		this.setSize(panel.getSize());
		init();
		
	}
	
	public void refreshPanel(JPanel panel){
		this.getRootPane().removeAll();
		this.setSize(panel.getWidth()-5, panel.getHeight()+15);
		this.getRootPane().add(panel);
		this.getRootPane().setBorder(new EmptyBorder(1, 1, 1, 1));
		this.validate();
	}
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
		public void run() {
			try {
				ClientFrame window = new ClientFrame();
				CenterController.setClient(window); //将窗口交给控制器管理
				window.refreshPanel(new LogonPanel());
				window.setVisible(true);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
	}

	public void refreshFriendsListPanel(JPanel panel) {
		this.getRootPane().removeAll();
		this.setSize(panel.getWidth()+5, panel.getHeight()+35);
		this.getRootPane().add(panel);
		this.validate();
	}

	private JMenuBar initJMenuBar() {
		JMenuBar bar = new JMenuBar();
		JMenu menu = new JMenu("111");
		JMenuItem item = new JMenuItem("2222");
		menu.add(item);
		bar.add(menu);
		return bar;
	}
	
}
